package cn.youframe.frame.ctrl;

import cn.youframe.frame.base.YFBase;
import cn.youframe.frame.service.DictService;
import cn.youframe.frame.util.SpringContext;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * User: Administrator
 * DateTime: 12-4-25: 下午3:18
 */
public class YouframeServlet extends HttpServlet implements YFBase {
    /**
     * Constructor of the object.
     */
    public YouframeServlet() {
        super();
    }

    /**
     * Destruction of the servlet. <br>
     */
    public void destroy() {
        super.destroy(); // Just puts "destroy" string in log
        // Put your code here
    }

    /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to get.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws javax.servlet.ServletException if an error occurred
     * @throws java.io.IOException if an error occurred
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws javax.servlet.ServletException if an error occurred
     * @throws java.io.IOException if an error occurred
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }

    /**
     * Initialization of the servlet. <br>
     *
     * @throws javax.servlet.ServletException if an error occure
     */
    public void init() throws ServletException {
        System.out.println("YouframeServlet init ....");
        initDictInfos();
    }

    /**
     * initDictInfos
     * 初始化字典表信息
     */
    public void initDictInfos() {
        try {
            logger.info("加载字典表信息");
            DictService dictService = SpringContext.getBean("dictService",DictService.class);
            dictService.initCache();
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        }
    }

}
